package GUI.TabPanels;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.jfree.data.category.CategoryDataset;

import reporting.BarGraph;

@SuppressWarnings("serial")
public class OccupancyPanel extends JPanel {

	private BarGraph graph;

	private JComboBox day_box;
	private JComboBox month_box;
	private JComboBox year_box;
	private JButton refresh;
	private JPanel center_center;

	private String [] days = {"1","2","3","4","5","6","7","8","9","10",
			"11","12","13","14","15","16","17","18","19","20",
			"21","22","23","24","25","26","27","28","29","30", "31"};
	private String [] months = {"1","2","3","4","5","6","7","8","9","10","11","12"};
	private String [] years = {"2012", "2013", "2014", "2015", "2016", "2017"};
	
	public OccupancyPanel(){
		this.setLayout(new BorderLayout());

		JPanel west = new JPanel();
		JPanel center = new JPanel();
		JPanel east = new JPanel();
		center_center = new JPanel();
		JPanel center_south = new JPanel();
		
		center.setLayout(new BorderLayout());
		
		graph = new BarGraph("Daily Occupancy Rate", "Hotel Name", "Occupancy Rate (%)");

		west.setBackground(new Color(147, 37, 37));
		west.add(new JLabel("        "));
		east.setBackground(new Color(147, 37, 37));
		east.add(new JLabel("        "));
		center_center.add(graph);
		center_center.setBackground(Color.black);

		day_box = new JComboBox(days);
		center_south.add(new JLabel("Day:"));
		center_south.add(day_box);
		month_box = new JComboBox(months);
		center_south.add(new JLabel("Month:"));
		center_south.add(month_box);
		year_box = new JComboBox(years);
		center_south.add(new JLabel(" Year:"));
		center_south.add(year_box);
		refresh = new JButton("Refresh");
		refresh.addActionListener(new RefreshButton());
		center_south.add(refresh);

		center.add(center_center, BorderLayout.CENTER);
		center.add(center_south, BorderLayout.SOUTH);

		this.add(west, BorderLayout.WEST);
		this.add(center, BorderLayout.CENTER);
		this.add(east, BorderLayout.EAST);
		
		CategoryDataset set = BarGraph.createDatasetForOccupancy(year_box.getSelectedItem() + "-" + month_box.getSelectedItem() + "-" + day_box.getSelectedItem(),
				year_box.getSelectedItem() + "-" + month_box.getSelectedItem() + "-" + day_box.getSelectedItem());
		graph.createChart(set);
		center_center.setVisible(false);
		center_center.setVisible(true);
	}
	
	class RefreshButton implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			CategoryDataset set = BarGraph.createDatasetForOccupancy(year_box.getSelectedItem() + "-" + month_box.getSelectedItem() + "-" + day_box.getSelectedItem(),
					year_box.getSelectedItem() + "-" + month_box.getSelectedItem() + "-" + day_box.getSelectedItem());
			graph.createChart(set);
			center_center.setVisible(false);
			center_center.setVisible(true);
		}
	}
}
